<?php

/*
Zoo Management Simulation
This is the Admin UI. It provides an overview of the cages and provides the user with adding, editing, deleting and securing doors options,
which are sent to the adminCageProcess file
The UI can also allow the user to call security which presents a small message box notifying them that security has been called
*/

include("dbconnect.php");
$sql = 'SELECT * FROM cage';
$result = mysql_query($sql);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function msg()
{
	alert("Security has been called please remain calm");
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoo Management Administator Page</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Zoo Management Administator Page</h1>
<?php
  echo "<form id='adminCageForm' name='adminCageForm' method='post' enctype='multipart/form-data' action='adminCageProcess.php'>";
      echo "<p><input type='number' name='maximum' id='maximum' value='".mysql_num_rows($result)."' />";
    echo "<input type='submit' name='submit' id='submit' value='Set maximum number of cages' /></p>";
  echo "<input type='submit' name='submit' id='submit' value='Add cage' />";
  echo "<input type='submit' name='submit' id='submit' value='Lock all doors' />";
  echo "<input type='button' value='Call Security' onclick='msg()' />";
  echo "</form>";
?>
<table id="zootable" width="100%" border="1">
  <tr>
    <td id="tableheader">Name</td>
    <td id="tableheader">Enclosure Number</td>
    <td id="tableheader">Length</td>
    <td id="tableheader">Width</td>
    <td id="tableheader">Height</td>
    <td id="tableheader">Type</td>
    <td id="tableheader">Number of entries</td>
    <td id="tableheader">Exhibit Name</td>
    <td id="tableheader">Exhibit Description</td>
    <td id="tableheader">Human Detector</td>
  </tr>
  
 <?php
  $cagenumber = 1;
		while(($row = mysql_fetch_row($result)) !== FALSE)
		{
			echo "<form id='CageForm' name='CageForm' method='post' enctype='multipart/form-data' action='adminCageProcess.php?id=".$row[0]."'>";
			echo "<tr>";
			echo "<td>" . "<a href='cage.php?cageid=".$row[0]."&cagenumber=". $cagenumber."&lighting=0' title='".$row[1]."'>". $row[1]. "</a></td>";
			echo "<td>". $cagenumber . "</td>";
			echo "<td>". $row[2]. "m</td>";
			echo "<td>".$row[3] . "m</td>";
			echo "<td>";
			if ($row[4] != 0){
				echo $row[4] . "m";
			}
			echo "</td>";
			
			echo "<td>";
			$typeresult = mysql_query("SELECT Type_Desc FROM type WHERE Type_Id='". $row[5] . "'");
			while (($typerow = mysql_fetch_row($typeresult)) !== FALSE)
			{
				echo $typerow[0];
			}
			echo "</td>";
			
			$countresult = mysql_query("SELECT Cage_Id FROM entry WHERE Cage_Id='". $row[0] . "'");
			echo "<td>". mysql_num_rows($countresult) . "</td>";
			echo "<td>". $row[6]. "</td>";
			echo "<td>". $row[7]. "</td>";
			echo "<td>". $row[8]. "</td>";
			
			echo "<input type='hidden' name='numberofentries' value='".mysql_num_rows($countresult) . "' />";
			
			echo "<td>". "<input type='submit' name='submit' id='submit' value='Edit' />" . "</td>";
			echo "<td>". "<input type='submit' name='submit' id='submit' value='Delete' />" . "</td>";
			echo "</tr>";
			echo "</form>";
			$cagenumber+=1;
		}
	?>        
        
</table>
</body>
</html>